home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Controls
/
Visual Basic Controls.iso
/
vbcontrol
/
polardrw
/
data.z
/
ScrollDemoDlg.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1999-05-24
|
7KB
|
255 lines
// ScrollDemoDlg.cpp : implementation file
//
#include "stdafx.h"
#include "ScrollDemo.h"
#include "ScrollDemoDlg.h"
#include "pdrawconst.h"
#include "math.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CScrollDemoDlg dialog
CScrollDemoDlg::CScrollDemoDlg(CWnd* pParent /*=NULL*/)
: CDialog(CScrollDemoDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CScrollDemoDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_nTimer = -1;
m_lLeftArrow = -1;
m_lSquare = -1;
m_lText = -1;
}
void CScrollDemoDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CScrollDemoDlg)
DDX_Control(pDX, IDC_POLARDRAWCTRL1, m_PolarDraw);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CScrollDemoDlg, CDialog)
//{{AFX_MSG_MAP(CScrollDemoDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_TIMER()
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CScrollDemoDlg message handlers
BOOL CScrollDemoDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// Here, we create shapes and set their attributes:
m_lSquare = m_PolarDraw.AddShape(polRectangle, 50, 50, 100, 100);
m_lLeftArrow = m_PolarDraw.AddShape(polLeftArrow, 105, 105, 205, 155);
if(m_lSquare > -1)
{
m_PolarDraw.SetShapeFillTexture(m_lSquare, polGreenMarble);
}
if(m_lLeftArrow > -1)
{
m_PolarDraw.SetShapeFillPattern(m_lLeftArrow, polSphere, RGB(255,0,0), RGB(255,255,0));
}
m_lText = m_PolarDraw.AddShape(polPlainText, 50, 50, 205, 155);
if (m_lText > 0)
{
m_PolarDraw.SetShapeText(m_lText, "Test");
m_PolarDraw.SetShapePos(m_lText, 50, 50, 205, 155);
m_PolarDraw.SetShapeLensType(m_lText, polInvert);
m_PolarDraw.SetShapeHasLens(m_lText, TRUE);
m_PolarDraw.SetShapeHasLine(m_lText, FALSE);
}
m_lDiamond = m_PolarDraw.AddShape(polDiamond, 50, 150, 205, 225);
if (m_lDiamond > 0)
{
m_PolarDraw.SetShapeFillType(m_lDiamond, polShade);
m_PolarDraw.SetShapeFillColor(m_lDiamond, RGB(255,0,0));
m_PolarDraw.SetShapeFillBackColor(m_lDiamond, RGB(255,255,0));
m_PolarDraw.SetShapeFillAngle(m_lDiamond, 90);
}
// Now set theoptimal zoom:
m_PolarDraw.FitToPage();
m_PolarDraw.SetEnableRendering(TRUE);
m_nTimer = SetTimer(1, 50, NULL);
return TRUE; // return TRUE unless you set the focus to a control
}
void CScrollDemoDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CScrollDemoDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CScrollDemoDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CScrollDemoDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if(nIDEvent == m_nTimer)
{
// disable rendering so the canvas is not redrawn after each line:
m_PolarDraw.SetEnableRendering(FALSE);
// Set shape attributes:
m_PolarDraw.RotateShape(m_lSquare, 5);
m_PolarDraw.RotateShape(m_lLeftArrow, -5);
m_PolarDraw.RotateShape(m_lText, 2);
long lRot1 = m_PolarDraw.GetShapeRotation(m_lLeftArrow);
long lRot2 = m_PolarDraw.GetShapeRotation(m_lText);
long lMove1 = (long)(30 * sin((float)lRot2/16));
m_PolarDraw.SetShapeLeft(m_lDiamond, 50 - lMove1);
m_PolarDraw.SetShapeRight(m_lDiamond, 205 + lMove1);
m_PolarDraw.SetShapeTop(m_lDiamond, 150 + lMove1/2);
m_PolarDraw.SetShapeBottom(m_lDiamond, 225 - lMove1/2);
// enable rendering now:
m_PolarDraw.SetEnableRendering(TRUE);
long lMove2 = (long)(40 * sin((float)lRot2/20));
long lMove3 = (long)(40 * cos((float)lRot2/20));
// following line will reposition the page inside the canvas
// and also re-render the canvas:
m_PolarDraw.SetPageOrigin(351 - lMove3, 395 - lMove2);
}
CDialog::OnTimer(nIDEvent);
}
void CScrollDemoDlg::OnDestroy()
{
CDialog::OnDestroy();
// Kill the timer that we created in OnInitialUpdate()
if(m_nTimer != -1)
KillTimer(m_nTimer);
}